﻿/*
 * 由SharpDevelop创建。
 * 用户： 汪伟威
 * 日期: 2015/4/28
 * 时间: 13:53
 * 
 */
using System;
using FluentNHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;


namespace NHibernateDemo
{
	/// <summary>
	/// Description of NHibernateHelper.
	/// </summary>
	public class NHibernateHelper
	{
		public static ISessionFactory CreateSessionFactory()
		{
			var item = Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("Demo")));
			item = item.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ProductMap>()).ExposeConfiguration(CreateSchema);
            return item.BuildSessionFactory();
		}

        private static void CreateSchema(Configuration cfg)
        {
            var schemaExport = new SchemaExport(cfg);
            //schemaExport.SetOutputFile("c:\\abc.sql");
            schemaExport.Create(false, false);
        }

		public NHibernateHelper()
		{

		}
	}
}
